<!DOCTYPE html>

<?php include "res/title.php"; ?>

<html>
<head>
	<title>GoDeal - <?php echo $title; ?></title>
	<meta charset="UTF-8">

	<link href='http://fonts.googleapis.com/css?family=Open+Sans&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
	<link rel="stylesheet" type="text/css" href="/css/style.css">
	<script type="text/javascript" src="/js/jquery-1.9.1.min.js"></script>
	<link rel="icon" type="image/png" href="/favicon.png" />
	<script src="/js/kkcountdown.min.js" type="text/javascript"></script>
	<script type="text/javascript">
	$(function() {
		$(".kkcount-down").each(function() {
			$(this).kkcountdown({
                	dayText		: 'день ',
                	daysText 	: 'дн ',
                    hoursText	: 'ч ',
                    minutesText	: 'мин ',
                    secondsText	: 'сек',
                    displayZeroDays : false,
                    oneDayClass	: 'one-day'
            });
		});
	});
	</script>

		<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
	<script type="text/javascript" src="/js/client-script.js"></script>
				<?php if($adeal->coord != "Some coordinates") { ?>	<style type="text/css">

#map-canvas {
	background: #333;
	height: 400px;
	width: 600px;
}

#map-canvas img { width: auto; display:inline; max-width: none; }
</style>
	<script type="text/javascript">

var marker;
var map;

function initialize() {

  var mapOptions = {
    zoom: 13,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    center: new google.maps.LatLng<?php echo $adeal->coord ?>
  };

  map = new google.maps.Map(document.getElementById('map-canvas'),
          mapOptions);
  

  marker = new google.maps.Marker({
    map:map,
    draggable:false,
    animation: google.maps.Animation.DROP,
    position: new google.maps.LatLng<?php echo $adeal->coord ?>
  });
}

//google.maps.event.addDomListener(window, 'load', initialize);
</script>

				<?php } ?>
</head>
<body onload="initialize()">

	<!-- Navigation -->
	<?php include "res/navigation.php"; ?>

	<div class="wrapper">
		<!-- Categories -->
		<?php include "res/categories.php"; ?>

		<!-- Right content -->
		<?php include "res/right-content.php" ?>

		<div class="container">
			<h1><?php echo $adeal->title ?></h1>
			
			<div class="deal-right-info">
				<a class="buy-button" onClick="buy()">Купить</a>
				<br>
				<br>
				<br>
				<h1>Купили: <?php echo count($this->coupon->getCouponByDealId($adeal->deal_id)) ?> </h1>
							
				<h3>Осталось: <br><span data-time="<?php echo date('U', strtotime(date('Y-m-d') .' +1 day')); ?>" class="kkcount-down"></span></h3>
				<br>
				<b>Сегодня:</b> <?= date('d.m.Y') ?>
				<br>
				<b>Время: </b> <?= date('H:i') ?>
			</div>

			<div class="img-holder" data-images="<?php echo count($images) + 1;?>">
				<img src="<?php echo $adeal->img_url ?>" class="first" data-image="0">
				<?php $i = 1; foreach ($images as $image): ?>
					<img src="<?php echo $image->img_url; ?>" data-image="<?php echo $i++ ?>">
				<?php endforeach ?>
				<div class="info">
					<?php if($adeal->i_cost > 0) { ?>
					<div class="i_cost">
						<?php echo $adeal->i_cost; ?> тг.
					</div>
					<?php } ?>
					<div class="s_cost">
						<?php echo $adeal->s_cost; ?> тг.
					</div>
				</div>

				<div class="controls">
					<div class="cbutton" onClick="prev_img()"> < </div>
					<div class="current"> 1 / <?php echo count($images) + 1;?> </div>
					<div class="cbutton" onClick="next_img()"> > </div>
				</div>
			</div>
			<div class="deal-menu">
				<div class="tab active" data-tab="1">Условия</div>
				<div class="tab" data-tab="2">Описание</div>
				<div class="tab" data-tab="3">Комментарии</div>
				<?php if($adeal->video) { ?>
				<div class="tab" data-tab="4">Видео</div> <?php } ?>
				<div class="tab" data-tab="5">О партнере</div>
			</div>
			<div class="tabs">
				<div class="tab-content active" id="tab-1">
					<?php echo $adeal->cond; ?>
				</div>
				<div class="tab-content" id="tab-2">
					<?php echo $adeal->specs; ?>
				</div>


				<div class="tab-content" id="tab-3">
					<?php $b = false;
					foreach ($comments as $comment) {
						if(!$comment->answer) continue;
						$b = true; ?>
						<div class="comment">
							<img src="/img/default-ava.png">
							<h4><?php echo $comment->user_name; ?></h4>
							<?php echo $comment->text; ?>
						</div>
						<div class="msg"><?php echo $comment->answer; ?></div>
					<?php } if(!$b) { ?>
						<div class="msg">Комментарев пока нет. Вы можете стать первым</div>
					<?php } ?>
					<div class="leave-comment">
					<?php if(!$session_name) { ?>
						<a href="" style="" onclick="to_link(0, 0)">Авторизируйтесь</a>, чтобы оставлять комментарии.
					<?php } else { ?>
						<form action="/godeal/deal/comment/<?php echo $adeal->id; ?>" method="post">
							<div class="comment">
							<?php if(!isset($session_avatar)) { ?>
								<img src="/img/default-ava.png">
							<?php } else { ?>
								<img src="<?php echo $session_avatar ?>">
							<?php } ?>
							<h4><?php echo $session_name; ?></h4>
							<textarea name="text" class="input" required></textarea>
							<input type="submit" class="comment-button" value="Оставить комментарий">
						</div>
						</form>
					<?php } ?>
					</div>
				</div>
				<div class="tab-content" id="tab-4">
					<iframe  width='500' height='320' src='<?php echo $adeal->video ?>' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>
				</div>
				<div class="tab-content" id="tab-5">
					<h3>Контактные номера</h3>
					<?php echo $adeal->tel; ?>
					<h3>Время работы</h3>
					<?php echo $adeal->time; ?>
					<h3>Адрес</h3>
					<?php echo $adeal->address; ?>
				</div>

				<?php if($adeal->coord != "Some coordinates") { ?>
				<div style="display: block">
					<h1>Карта</h1>
			    	<div id="map-canvas"></div>
				</div>
				<?php } ?>
			</div>
		</div>

		<!-- Footer -->
		<?php include "res/footer.php"; ?>
	</div>
	
	<!-- Popup Login -->
	<?php include "res/popup-login.php" ?>

	<!-- Popup Buy -->
	<div class="popup-buy">
		<p>&times;</p>
	</div>

	<div class="buy-form">
		<h2>| Купить</h2>
		<p>
			<table cellspacing='0'>
				<?php if ($adeal->i_cost > 0): ?>
					<thead>
						<td>Наименование</td>
						<td>Цена без скидки</td>
						<td>Скидка</td>
						<td>Цена сертификата</td>
						<td></td>
					</thead>
					<?php foreach ($products as $product): ?>
					<tr>
						<td><?php echo $product->name ?></td>
						<td><?php echo $product->cost ?></td>
						<td><?php echo $product->discount ?>%</td>
						<td><?php echo $product->cost / 100 * (100 - $product->discount) ?></td>
						<td><a href="/godeal/home/choosePayment/product/<?php echo $product->prod_id ?>" class="buy-button small">Купить</a></td>
					</tr>
					<?php endforeach ?>
				<?php endif ?>
				<?php if ($adeal->i_cost < 1): ?>
					<thead>
						<td>Наименование</td>
						<td>Цена купона</td>
						<td></td>
					</thead>
					<?php foreach ($products as $product): ?>
					<tr>
						<td><?php echo $product->name ?></td>
						<td><?php echo $product->cost ?></td>
						<td><a href="/godeal/home/choosePayment/product/<?php echo $product->prod_id ?>" class="buy-button small">Купить</a></td>
					</tr>
					<?php endforeach ?>
				<?php endif ?>
			</table>
		</p>
	</div>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-41962264-1', 'godeal.kz');
  ga('send', 'pageview');

</script>
	
</body>
</html>